package pages

type PageDTO struct {
	PageNum  int `json:"pageNum" form:"pageNum" query:"pageNum"`
	PageSize int `json:"pageSize" form:"pageSize" query:"pageSize"`
}

func (p *PageDTO) GetOffsetAndLimit() (offset int, limit int) {
	return (p.PageNum - 1) * p.PageSize, p.PageSize
}

func GetOffsetAndLimitByPageDTO(p *PageDTO) (offset int, limit int) {
	return (p.PageNum - 1) * p.PageSize, p.PageSize
}

func GetOffsetAndLimit(pageNum int, pageSize int) (offset int, limit int) {
	return (pageNum - 1) * pageSize, pageSize
}

type Page[T any] struct {
	Records []*T  `json:"records"`
	Total   int64 `json:"total"`
	Size    int   `json:"size"`
	Current int   `json:"current"`
}

func NewPage[T any](records []*T, total int64, current int, size int) *Page[T] {
	return &Page[T]{
		Records: records,
		Total:   total,
		Size:    size,
		Current: current,
	}
}

//simple
//type UserPageDTO struct {
//	PageDTO
//	DeptID string `json:"deptId" form:"deptId" query:"deptId"`
//}
